package linknode;

public class LinkNodeMerge {

    public LinkNode mergeTwoLists(LinkNode l1, LinkNode l2) {
        // 临时节点
        LinkNode dummy = new LinkNode(0);
        // 指针
        LinkNode current = dummy;

        while (l1 != null && l2 != null) {
            if (l1.data < l2.data) {
                current.next = l1;
                l1 = l1.next;
            } else {
                current.next = l2;
                l2 = l2.next;
            }
            current = current.next;
        }

        if (l1 != null) {
            current.next = l1;
        } else {
            current.next = l2;
        }

        return dummy.next;
    }

}
